package com.hzy.admin.controller;

import com.hzy.admin.services.system.ISysMenuService;
import com.hzy.framework.annotation.UserAuthorization;
import com.hzy.framework.controller.ViewController;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.Map;

/**
 * 接口基础类
 *
 * @author hzy
 */
@UserAuthorization
public class ApiBaseController<TService> extends ViewController {
    @Autowired
    protected ISysMenuService sysMenuService;
    protected TService service;
    private final String menuId;

    public ApiBaseController() {
        super();
        this.menuId = null;
    }

    public ApiBaseController(String menuId, TService service) {
        super();
        this.menuId = menuId;
        this.service = service;
    }

    public ApiBaseController(String menuId, TService service, String viewPrefix) {
        super(viewPrefix);
        this.menuId = menuId;
        this.service = service;
    }

    /**
     * 获取 页面权限 及 按钮权限
     *
     * @return 按钮 及 页面 权限 字典
     */
    public Map<String, Boolean> getPower() {
        if (StringUtils.isEmpty(this.menuId)) {
            return new HashMap<String, Boolean>(0);
        }
        return this.sysMenuService.getPowerByMenuId(this.menuId);
    }

}
